<?php

namespace App\Http\Middleware;

use Closure;
use Tymon\JWTAuth\Http\Middleware\BaseMiddleware;

class Authenticate extends BaseMiddleware
{
    /**
     * The names of the cookies that should not be encrypted.
     * @var array
     */
    public function handle($request, Closure $next, $guard = null)
    {
        try {
            $this->checkForToken($request);
            if (!$user = $this->auth->parseToken()->authenticate()) {
                return response()->json([
                    'msg'  => 'need_login',
                    'code' => 401,
                    'data' => null,
                ], 401);
            }
        } catch (\Exception $e) {

            return response()->json([
                'msg'  => 'need_login',
                'code' => 401,
                'data' => null,
            ], 401);

        }
        $response = $next($request);
        return $response;
    }
}
